home *** CD-ROM | disk | FTP | other *** search
- // note that comments come from Ed Ringel (ERR) and Apple. Anything from ERR will be labelled as such
-
- #include "BTreeDef.h"
- #include "BTreeProtos.h"
- #include "StandardFile.h"
-
- #include "SampleHeader.h"
- #include "InvoiceGlobals.h"
- #include "Actions.h"
- #include "NOC.h"
-
-
- /* In the 68K world, this is provided for you as part of your A5 world, but */
- /* on the PowerPC, you have to explicitly include it. */
- #ifdef __powerc
- QDGlobals qd;
- #endif
-
- /* Two globals. One always tells me whether I'm in the background or not */
- /* (maintained in the Suspend/Resume event handler in MainEventLoop()), and */
- /* another that allows me to cleanly drop out of my main event loop from */
- /* anywhere. Sure ExitToShell() works, too, but I like to exit in only one */
- /* way, and this global allows me to do that.*/
- // (ERR) these are in the Global Data.c file
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void main()
- {
-
- InitApplication();
- PreEventLoop();
- MainEventLoop();
- }
-
-
- /*-------------------------------------------------------------------------------------*/
- /*
- InitApplication - initializes the toolbox, my globals, and my menu bar.
- */
- void InitApplication()
- {
- Handle theMenu;
-
- // Toolbox initialization
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(0,everyEvent);
-
- // Application initialization
- gDone = false;
- gInBackground = false;
-
- theMenu = GetNewMBar(kMenuBarResID);
- if ( theMenu != nil )
- {
- SetMenuBar(theMenu);
- AddResMenu(GetMHandle(kAppleMenuID), 'DRVR');
- DrawMenuBar();
- }
- else
- /* If the menu stuff failed, something just ain't */
- /* right (most likely some resources are missing). */
- gDone = true;
-
- }
-
-
- /*-------------------------------------------------------------------------------------*/
- /*
- DoAboutBox - I just have an Alert dialog box set up in my resources for this.(ERR)
- */
- void DoAboutBox()
- {
- short AlertReturn = Alert(kAboutBoxDITLID, nil);
- }
-
-
- /*-------------------------------------------------------------------------------------*/
- /*
- MainEventLoop - handles all events for this application. Note that the first
- thing done with an event is to check if it belongs to a dialog, and if so the
- event is passed to DoDialogEvent() which handles all dialog events except
- null events. To check if it's a dialog event, the IsDialogEvent routine is
- called which checks to see if the frontmost window is a dialog and if the
- event is not an update, a mousedown or an activate for another window. Note
- that null events are all passed to DoDialogNullEvent, which is needed to keep
- the editText cursor blinking..
-
- */
- void MainEventLoop()
- {
- EventRecord theEvent;
- WindowPtr thisWindow;
- short clickArea;
- Rect screenRect;
- long menuResult;
- char charCode;
-
- while ( !gDone )
- {
- if ( WaitNextEvent(everyEvent, &theEvent, 0, nil) )
- {
- if ( IsDialogEvent(&theEvent) == true )
- {
- DoDialogEvent(&theEvent);
- continue;
- }
-
- switch (theEvent.what)
- {
- case mouseDown:
- clickArea = FindWindow(theEvent.where, &thisWindow);
-
- switch ( clickArea )
- {
- case inDrag:
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow(thisWindow, theEvent.where, &screenRect);
- break;
- case inContent:
- if ( thisWindow != FrontWindow() )
- SelectWindow(thisWindow);
- break;
- case inGoAway:
- if ( TrackGoAway(thisWindow, theEvent.where) == true )
- {
- if ( ((WindowRecord *)thisWindow)->windowKind == dialogKind )
- DisposeDialog(thisWindow);
- else
- gDone = true;
- }
- break;
- case inMenuBar:
- menuResult = MenuSelect(theEvent.where);
- if ( (menuResult >> 16) != 0 )
- (void) MenuCommand(menuResult);
- break;
- case inSysWindow:
- SystemClick(&theEvent,thisWindow);
- break;
- }
-
- break;
- case keyDown:
- charCode = theEvent.message & charCodeMask;
-
- if ( (theEvent.modifiers & cmdKey) != 0 )
- {
- menuResult = MenuKey(charCode);
-
- if ( (menuResult >> 16) != 0 )
- (void) MenuCommand(menuResult);
-
- }
- break;
- case updateEvt:
- break;
- case diskEvt:
- // added by ERR; file oriented program
- if (HiWord(theEvent.message) != noErr) {
- Point diskInitPt = {0,0};
- DILoad();
- DIBadMount(diskInitPt, theEvent.message);
- DIUnload();
- }
- break;
- case app4Evt:
- /* Make sure the SIZE resource reflects that suspend evts are accepted.*/
- if ( theEvent.message & 0x01000000 ) /* Suspend or resume? */
- {
- if ( theEvent.message & 0x00000001 )/* Is it a resume event? */
- {
- gInBackground = false;
- SetCursor(&qd.arrow);
- }
- else /* It's a suspend event */
- gInBackground = true;
-
- }
- break;
- }
- }
- else
- DoDialogNullEvent(&theEvent);
- }
- }
-
-
-
- /*-------------------------------------------------------------------------------------*/
- /*
- MenuCommand - called in response to keydowns in both my dialog event handler and
- the main event loop. Note that because of AdjustMenus(), the edit keys will only
- be hit if the dialog is the frontmost window, which is what we want.
-
-
-
- */
-
- #define kActivate 1
- #define kInactivate 2
-
-
-
-
- Boolean MenuCommand(long whaHappened)
- {
- short menuID, menuItem;
- Boolean performedEdit = false;
- DialogPtr theDialog;
- short menuErr;
-
- menuID = (whaHappened >> 16);
- menuItem = (whaHappened & 0xFFFF);
-
- switch ( menuID )
- {
- case kAppleMenuID:
- HiliteMenu(kAppleMenuID);
- if ( menuItem == 1)
- DoAboutBox();
- break;
-
- case kFileMenuID:
- HiliteMenu(kFileMenuID);
- switch ( menuItem )
- {
- case kNewItem:
- menuErr = NewFile();
- if (menuErr) {
- HandleErrorMsg(menuErr);
- break;
- }
- DisableItem(gFileMenu,kNewItem);
- DisableItem(gFileMenu,kOpenItem);
- EnableItem(gFileMenu,kCloseItem);
- ToggleControl(gCustomerDialog,1,kActivate);
- ToggleControl(gPartDialog,1,kActivate);
- ToggleControl(gInvoiceDialog,1,kActivate);
- break;
- case kOpenItem:
- menuErr = OpenFile();
- if (menuErr) {
- HandleErrorMsg(menuErr);
- break;
- }
- DisableItem(gFileMenu,kNewItem);
- DisableItem(gFileMenu,kOpenItem);
- EnableItem(gFileMenu,kCloseItem);
- ToggleControl(gCustomerDialog,1,kActivate);
- ToggleControl(gPartDialog,1,kActivate);
- ToggleControl(gInvoiceDialog,1,kActivate);
- break;
-
- case kCloseItem:
- menuErr = CloseFile();
- if (menuErr) {
- HandleErrorMsg(menuErr);
- break;
- }
- EnableItem(gFileMenu,kNewItem);
- EnableItem(gFileMenu,kOpenItem);
- DisableItem(gFileMenu,kCloseItem);
- ToggleControl(gCustomerDialog,1,kInactivate);
- ToggleControl(gPartDialog,1,kInactivate);
- ToggleControl(gInvoiceDialog,1,kInactivate);
- break;
-
- case kQuitItem:
- gDone = true;
- if (gFileIsOpen)
- menuErr = CloseFile();
- break;
- }
- break;
- case kEditMenuID:
- // This thing should be a dialog, because the menu items are
- // disabled unless a modeless dialog is frontmost.
- theDialog = (DialogPtr)FrontWindow();
-
- if ( theDialog != nil )
- {
- HiliteMenu(kEditMenuID);
- switch ( menuItem )
- {
- case kCutItem:
- DoCut(theDialog);
- performedEdit = true;
- break;
- case kCopyItem:
- DoCopy(theDialog);
- performedEdit = true;
- break;
- case kPasteItem:
- DoPaste(theDialog);
- performedEdit = true;
- break;
- case kClearItem:
- DoClear(theDialog);
- performedEdit = true;
- break;
- }//switch
- }//if
- break;
- case kWindowMenuID:
- switch ( menuItem) {
- case kCustomerWindowID:
- SelectWindow(gCustomerDialog);
- break;
- case kPartWindowID:
- SelectWindow(gPartDialog);
- break;
- case kInvoiceWindowID:
- SelectWindow(gInvoiceDialog);
- break;
- case kPictureWindowID:
- HandlePictureDialog();
- break;
- }
- break;
- }
- HiliteMenu(0);
- return performedEdit;
- }
-
-
-
-
- /*-------------------------------------------------------------------------------------*/
-
- /*-------------------------------------------------------------------------------------*/
-
- void PreEventLoop(void)
- {
- //CreateNewWindow();
- CreateModelessDialog(kCustomerDLGID,&gCustomerDialog);
- CreateModelessDialog(kPartDLGID,&gPartDialog);
- CreateModelessDialog(kInvoiceDLGID,&gInvoiceDialog);
- gFileMenu = GetMenuHandle(kFileMenuID);
- gEditMenu = GetMenuHandle(kEditMenuID);
- gWindowMenu = GetMenuHandle(kWindowMenuID);
- ToggleControl(gCustomerDialog,1,kInactivate);
- ToggleControl(gPartDialog, 1, kInactivate);
- ToggleControl(gInvoiceDialog,1,kInactivate);
- }
-
-
- /*-------------------------------------------------------------------------------------*/
-
- void PostEventLoop(void)
- {
- }
-
-
- /*-------------------------------------------------------------------------------------*/
-
-